#include<bits/stdc++.h>
using namespace std;
int T,n,sa[1050000],rk[1050000],p[1050000],q[1050000];
bool chk() {
    static bool f[1050000];
    for (int i=0;i<n;i++) {
        if ((sa[i]<0)||(sa[i]>=n)) return false;
        if (f[sa[i]]) return false;
        f[sa[i]]=true;
        rk[sa[i]]=i;
    }
    for (int i=0;i<n;i++) f[sa[i]]=false;
    for (int i=0;i<n-1;i++) if (q[i]%2) return false;
    for (int i=0;i<n;i++) if (p[i]%2==0) return false;
    for (int i=0;i<n;i++) p[i]/=2;
    for (int i=0;i<n-1;i++) q[i]/=2;
    return true;
}
vector<int> ed[1050000];
int g[1050000],u,v,lst,ans[1050000];
bool chkres() {
    static int tmp[2050000],res[2050000],maxp;
    for (int i=0;i<n;i++) {
        tmp[i*2+1]=ans[i];
        tmp[i*2]=0;
        res[i*2]=res[i*2+1]=0;
    }
    tmp[n*2]=res[n*2]=0;maxp=0;
    for (int i=1;i<=n*2;i++) {
        if (i<=maxp+res[maxp]) res[i]=min(res[maxp+maxp-i],maxp+res[maxp]-i);
        else res[i]=0;
        while ((i-res[i]-1>=0)&&(i+res[i]+1<=n*2)&&(tmp[i-res[i]-1]==tmp[i+res[i]+1])) res[i]++;
        if (i+res[i]>maxp+res[maxp]) maxp=i;
    }
    for (int i=0;i<n;i++) {
        if (res[i*2+1]!=p[i]*2+1) return false;
    }
    for (int i=0;i<n-1;i++) {
        if (res[i*2+2]!=q[i]*2) return false;
    }
    return true;
}
int main() {
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    scanf("%d",&T);
    while (T--) {
        scanf("%d",&n);
        for (int i=0;i<n;i++) scanf("%d",&sa[i]);
        for (int i=0;i<n-1;i++) scanf("%d%d",&p[i],&q[i]);
        scanf("%d",&p[n-1]);
        if (!chk()) {
            printf("-1\n");
            continue;
        }
        for (int i=0;i<n-1;i++) {
            if (sa[i]<n-1) {
                if (sa[i+1]==n-1) ed[i+1].push_back(i);
                else if (rk[sa[i+1]+1]<rk[sa[i]+1]) ed[i+1].push_back(i);
            }
        }
        for (int i=0;i<n;i++) {
            if (p[i]<min(i,n-i-1)) {
                u=i-p[i]-1;v=i+p[i]+1;
                if (rk[u]>rk[v]) swap(u,v);
                ed[rk[v]].push_back(rk[u]);
            }
        }
        for (int i=0;i<n-1;i++) {
            if (q[i]<min(i+1,n-i-1)) {
                u=i-q[i];v=i+q[i]+1;
                if (rk[u]>rk[v]) swap(u,v);
                ed[rk[v]].push_back(rk[u]);
            }
        }
        g[0]=1;lst=0;
        for (int i=1;i<n;i++) {
            for (auto x:ed[i]) {
                if (x>=lst) g[i]=1;
            }
            if (g[i]) lst=i;
        }
        for (int i=1;i<n;i++) g[i]+=g[i-1];
        if (g[n-1]>26) {
            printf("-1\n");
            for (int i=0;i<n;i++) {
                ed[i].clear();
                g[i]=0;
            }
            continue;
        } else {
            for (int i=0;i<n;i++) ans[i]=g[rk[i]];
            if (!chkres()) {
                printf("-1\n");
                for (int i=0;i<n;i++) {
                    ed[i].clear();
                    g[i]=0;
                }
                continue;
            }
            for (int i=0;i<n;i++) printf("%c",'a'-1+ans[i]);
            printf("\n");
        }
        for (int i=0;i<n;i++) {
            ed[i].clear();
            g[i]=0;
        }
    }
    return 0;
}
